home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / doc / uplevel.n < prev    next >
Text File  |  1993-06-16  |  4KB  |  80 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/uplevel.n,v 1.1 93/06/16 16:48:27 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS uplevel tcl
  25. .BS
  26. '\" Note:  do not modify the .SH NAME line immediately below!
  27. .SH NAME
  28. uplevel \- Execute a script in a different stack frame
  29. .SH SYNOPSIS
  30. \fBuplevel \fR?\fIlevel\fR?\fI arg \fR?\fIarg ...\fR?
  31. .BE
  32.  
  33. .SH DESCRIPTION
  34. .PP
  35. All of the \fIarg\fR arguments are concatenated as if they had
  36. been passed to \fBconcat\fR; the result is then evaluated in the
  37. variable context indicated by \fIlevel\fR.  \fBUplevel\fR returns
  38. the result of that evaluation.
  39. .PP
  40. If \fIlevel\fR is an integer then
  41. it gives a distance (up the procedure calling stack) to move before
  42. executing the command.  If \fIlevel\fR consists of \fB#\fR followed by
  43. a number then the number gives an absolute level number.  If \fIlevel\fR
  44. is omitted then it defaults to \fB1\fR.  \fILevel\fR cannot be
  45. defaulted if the first \fIcommand\fR argument starts with a digit or \fB#\fR.
  46. .PP
  47. For example, suppose that procedure \fBa\fR was invoked
  48. from top-level, and that it called \fBb\fR, and that \fBb\fR called \fBc\fR.
  49. Suppose that \fBc\fR invokes the \fBuplevel\fR command.  If \fIlevel\fR
  50. is \fB1\fR or \fB#2\fR  or omitted, then the command will be executed
  51. in the variable context of \fBb\fR.  If \fIlevel\fR is \fB2\fR or \fB#1\fR
  52. then the command will be executed in the variable context of \fBa\fR.
  53. If \fIlevel\fR is \fB3\fR or \fB#0\fR then the command will be executed
  54. at top-level (only global variables will be visible).
  55. .PP
  56. The \fBuplevel\fR command causes the invoking procedure to disappear
  57. from the procedure calling stack while the command is being executed.
  58. In the above example, suppose \fBc\fR invokes the command
  59. .DS
  60. \fBuplevel 1 {set x 43; d}
  61. .DE
  62. where \fBd\fR is another Tcl procedure.  The \fBset\fR command will
  63. modify the variable \fBx\fR in \fBb\fR's context, and \fBd\fR will execute
  64. at level 3, as if called from \fBb\fR.  If it in turn executes
  65. the command
  66. .DS
  67. \fBuplevel {set x 42}
  68. .DE
  69. then the \fBset\fR command will modify the same variable \fBx\fR in \fBb\fR's
  70. context:  the procedure \fBc\fR does not appear to be on the call stack
  71. when \fBd\fR is executing.  The command ``\fBinfo level\fR'' may
  72. be used to obtain the level of the current procedure.
  73. .PP
  74. \fBUplevel\fR makes it possible to implement new control
  75. constructs as Tcl procedures (for example, \fBuplevel\fR could
  76. be used to implement the \fBwhile\fR construct as a Tcl procedure).
  77.  
  78. .SH KEYWORDS
  79. context, stack frame, variables
  80.